<template>
	<view class="container">
		<view class="courses-list flex-space-b flex-wrap">
			<course-column v-for="item in listData" :key="item.id" :item="item" :show-btn="false" />
		</view>
		<view class="empty-box">
			<u-empty v-if="loadData.status === 'nodata'" text="暫無數據" mode="data" icon="https://cdn.uviewui.com/uview/empty/data.png" />
			<u-loadmore
				v-else
				loadingIcon="circle"
				color="#aaa"
				:status="loadData.status"
				:loading-text="loadData.loadingText"
				:nomore-text="loadData.nomoreText"
			/>
		</view>
		<!-- 登录弹窗 -->
		<login-pop />
		<!-- 协议弹窗 -->
		<protocol-pop />
	</view>
</template>

<script>
	import CourseColumn from '@/components/Course/column'
	import { getMyFavorites } from '@/api/user'
	export default {
		components: {
			CourseColumn
		},
		data() {
			return {
				listData: [],
				loadData: {
					status: 'loading',
					loadingText: '努力加載中',
					nomoreText: '沒有更多了'
				}
			}
		},
		async onShow() {
			this.getList()
		},
		methods: {
			async getList() {
				const { data } = await getMyFavorites({}, { needLoading: false })
				if (data.length === 0) {
					this.loadData.status = 'nodata'
					this.listData = []
					return
				}
				this.listData = data
				this.loadData.status = 'nomore'
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		min-height: 100vh;
		background: #fff;
		padding-bottom: 20rpx;
		box-sizing: border-box;
	}

	.courses-list {
		padding: 20rpx;
	}
	/deep/ .empty-box .u-empty {
		height: 70vh;
	}
</style>